package com.ajaxjs.cms.controller;

import java.util.HashMap;
import java.util.Map;

import javax.mvc.annotation.Controller;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;

import com.ajaxjs.cms.service.HrService;
import com.ajaxjs.config.ConfigService;
import com.ajaxjs.framework.model.ModelAndView;
import com.ajaxjs.mvc.controller.CommonController;
import com.ajaxjs.util.logger.LogHelper;

/**
 * just a json
 * 
 * @author xinzhang
 *
 */
@Controller
@Path("/admin/hr")
public class HrAdminController extends CommonController<Map<String, Object>, Long> {
	private static final LogHelper LOGGER = LogHelper.getLog(HrAdminController.class);
	
	public HrAdminController() {
		setAdminUI(true);
	}

	@Override
	public HrService getService() {
		// 单例
		/*
		 * if(super.getService() == null) setService(new NewsAdminService());
		 * return (NewsAdminService) super.getService();
		 */

		return new HrService();
	}

	@GET
	@Path("list")
	public String list(@QueryParam("start") int start, @QueryParam("limit") int limit, ModelAndView model) {
		CatalogController.initCatalog(ConfigService.getValueAsInt("data.jobCatalog_Id"), model, true);
		
		return super.list(start, limit, model);
	}

	/**
	 * 新建
	 */
	@GET
	@Override
	public String createUI(ModelAndView model) {
		CatalogController.initCatalog(ConfigService.getValueAsInt("data.jobCatalog_Id"), model);

		return super.createUI(model);
	}

	@POST
	@Override
	public String create(Map<String, Object> news, ModelAndView model) {
		return super.create(news, model);
	}

	/**
	 * 编辑
	 */
	@GET
	@Path("{id}")
	@Override
	public String info(@PathParam("id") Long id, ModelAndView model) {
		LOGGER.info("后台管理-修改 UI");
		model.put("isCreate", false);

		CatalogController.initCatalog(ConfigService.getValueAsInt("data.jobCatalog_Id"), model);

		return super.info(id, model);
	}

	@PUT
	@Path("{id}")
	@Override
	public String update(Map<String, Object> news, ModelAndView model) {
		return super.update(news, model);
	}

	@DELETE
	@Path("{id}")
	public String delete(@PathParam("id") Long id, ModelAndView model) {
		Map<String, Object> news = new  HashMap<String, Object>(); // 删除比较特殊
		news.put("id", id);
		return delete(news, model);
	}
}
